package com.lwt.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lwt.gulimall.product.entity.SkuImages;
import com.lwt.gulimall.product.service.SkuImagesService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lwt.gulimall.common.utils.R;



/**
 * sku图片
 *
 * @author liuweitao
 * @email liuweitao2541@gmail.com
 * @date 2024-01-26 16:11:42
 */
@RestController
@RequestMapping("product/skuimages")
public class SkuImagesController {
    @Autowired
    private SkuImagesService skuImagesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        long pageSize = Long.parseLong((String)params.get("page"));
        long limit = Long.parseLong((String)params.get("limit"));
        Page<SkuImages> page = new Page<>(pageSize,limit);
        Page<SkuImages> pageResult = skuImagesService.page(page, null);

        return R.ok().put("page", pageResult);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SkuImages skuImages = skuImagesService.getById(id);

        return R.ok().put("skuImages", skuImages);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SkuImages skuImages){
		skuImagesService.save(skuImages);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody SkuImages skuImages){
		skuImagesService.updateById(skuImages);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		skuImagesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
